package com.lanchetech.common.util;

import java.util.HashMap;
import java.util.UUID;

public class ThreadContext {
    private static ThreadLocal<HashMap<String, String>> contextThreadLocal = ThreadLocal.withInitial(() -> new HashMap<>());

    public static final String REQ_UUID = "req_uuid";

    public static String generateRequestUUID() {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        contextThreadLocal.get().put(REQ_UUID, uuid);

        return uuid;
    }

    public static String set(String name, String val) {
        return contextThreadLocal.get().put(name, val);
    }

    public static String get(String id) {
        return contextThreadLocal.get().get(id);
    }
}
